package main

import "fmt"

//函数的也是一种数据类型
func main() {

	fun := getSum
	fmt.Printf("fun %T getSum %T  ", fun, getSum)
	fmt.Println(fun(123, 123))

	res1 := myFunc(getSum, 123, 123)

	fmt.Println(res1)

	//使用 _ 忽略返回值
	_, sub := getSumAndSub(343, 23)
	fmt.Println("sum")
	fmt.Println("sub", sub)

	fmt.Println("myFuncTypeInvoke")
	result3 := myFuncTypeInvoke(getSum, 323, 232)
	fmt.Println("result3==", result3)
}

func getSum(n1 int, n2 int) int {
	return n1 + n2
}

func myFunc(funvar func(int, int) int, num1 int, num2 int) int {
	return funvar(num1, num2)
}

type myFuncType func(int, int) int

func myFuncTypeInvoke(invokeFunc myFuncType, n1 int, n2 int) int {
	return invokeFunc(n1, n2)
}

//返回值命名

func getSumAndSub(n1 int, n2 int) (sum int, sub int) {
	sum = n1 + n2
	sub = n1 - n2
	return
}
